﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using CommunityToolkitMvvmDemo.Common;
using CommunityToolkitMvvmDemo.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace CommunityToolkitMvvmDemo.ViewModels
{
   public  partial  class MainViewModel:ObservableObject
    {
        [RelayCommand]
        public void Close()=> App.Current.Shutdown();

        [RelayCommand]
        public void Min() => Application.Current.MainWindow.WindowState = WindowState.Minimized;

        [RelayCommand]
        void Max()
        {
            _ = Application.Current.MainWindow.WindowState == WindowState.Maximized ?
                Application.Current.MainWindow.WindowState = WindowState.Normal :
                Application.Current.MainWindow.WindowState = WindowState.Maximized;
        }

        [RelayCommand]
        void Move(object win)
        {
            (win as Window).DragMove();
        }

        [ObservableProperty]
        private Person userInfo;
             

        [ObservableProperty]
        private FrameworkElement mainContent;

        public MainViewModel()
        {
            this.userInfo = new Person();
            UserInfo = GlobalValues.UserInfo;

            NavChanged("HomePage");
        }

        [RelayCommand]
        void NavChanged( object obj)
        {
            Type type = Type.GetType("CommunityToolkitMvvmDemo.UserControls."+obj.ToString());
            ConstructorInfo cti = type.GetConstructor(System.Type.EmptyTypes);
            MainContent =(FrameworkElement) cti.Invoke(null);
        }
    }
}
